package com.dayaokeji.rhythmschoolstudent.client.home.helper

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.Menu
import android.view.MenuItem
import com.dayaokeji.rhythmschoolstudent.R
import com.dayaokeji.rhythmschoolstudent.client.common.base.common.BaseActivity
import com.dayaokeji.rhythmschoolstudent.utils.ToastUtils
import kotlinx.android.synthetic.main.activity_course_sign_failed_helper.*
import kotlinx.android.synthetic.main.fragment_helper_step_one.*

/**
 * 课程签到失败帮助
 */
class CourseSignFailedHelperActivity : BaseActivity() {

    private val helperFragments: ArrayList<Fragment> = arrayListOf(
            HelperStepOneFragment.newInstance(),
            HelperStepTwoFragment.newInstance(),
            HelperStepThreeFragment.newInstance(),
            HelperStepFourFragment.newInstance(),
            HelperStepFifthFragment.newInstance()
    )

    private var index = 0;

    companion object {
        fun navigation(cxt: Context) {
            val intent = Intent(cxt, CourseSignFailedHelperActivity::class.java)
            cxt.startActivity(intent)
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_course_sign_failed_helper)
        setSupportActionBar(toolbar)
        init()
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.menu_previous,menu)
        return super.onCreateOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        item?.let {
            when (it.itemId) {
                R.id.menu_previous -> {
                    if (index >0) {
                        index -= 1
                        vpCourseFailedHelper.setCurrentItem(index,true)
                    }else{
                        ToastUtils.info("别点啦，已是第一页了 ^_^！")
                    }
                }
            }
        }
        return super.onOptionsItemSelected(item)
    }

    private fun init() {
        setupView()
        setOnListener()
    }

    private fun setupView() {
        vpCourseFailedHelper.adapter = HelperViewPagerAdapter(supportFragmentManager,helperFragments)
    }

    private fun setOnListener() {

    }

    fun nextPage() {
        if (index < helperFragments.size-1) {
            index += 1
            vpCourseFailedHelper.setCurrentItem(index,true)
        }
    }
}
